﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace CarparkIMS_CMS
{
    public class Program
    {


        public CancellationToken cancellationToken = new CancellationToken(false);
        public static void Main(string[] args)
        {
            //  string dd=Controllers.AccountController.MD5Encrypt("123456");
            // System.IO.File.WriteAllText("d:\\admin.txt", "[123456]password:"+dd);
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    //webBuilder.UseSetting("http_port", "5000");
                    //webBuilder.UseSetting("https_port", "5001");

                    webBuilder.UseStartup<Startup>();

                }).ConfigureServices((hostContext, services) =>
                {
                    //services.AddHostedService<Worker>();  //2023年3月6日=============临时屏蔽

                    DateTime dt = new DateTime(2023, 6, 1);
                    if (dt > DateTime.Now)
                    {
                        while (true)
                        {
                            Console.WriteLine("INPUT ENTER TO RUN BACKGROUND SERVICE.....\n");
                            Console.WriteLine("\nSETTING : https://localhost:5001/camerasetting \n");

                            ConsoleKeyInfo consoleKeyInfo = new ConsoleKeyInfo();
                            consoleKeyInfo = Console.ReadKey();
                            if (consoleKeyInfo.Key == ConsoleKey.Enter)
                            {
                                //services.AddHostedService<Worker>();
                                //-----------------------------------------------------------
                                services.AddHostedService<ScopedWokerService>();
                                break;
                            }

                            if (consoleKeyInfo.Key == ConsoleKey.Spacebar)
                                break;
                        }
                    }
                    else
                    {
                        //services.AddHostedService<Worker>();
                        services.AddHostedService<ScopedWokerService>();
                    }
                });
    }
}
